#pragma once

#include <sys/epoll.h>
#include <memory>
#include <string>
#include "InetAddr.hpp"

class Reactor;

using handler_t = std::function<std::string(std::string &)>;
// Connetion作为虚基类，派生类Listener等
class Connection
{
public:
    Connection()
    {
    }
    virtual void Recver() = 0;
    virtual void Sender() = 0;
    virtual void Excepter() = 0;
    virtual int GetFd() = 0;

    void SetEvents(uint32_t events)
    {
        _events = events;
    }
    uint32_t GetEvents()
    {
        return _events;
    }
    void SetOwner(Reactor *owner)
    {
        _owner = owner;
    }
    Reactor *GetOwner()
    {
        return _owner;
    }
    void RegisterHandler(handler_t h)
    {
        _handler = h;
    }

    ~Connection()
    {
    }

private:
    // 回指指针
    Reactor *_owner;

    // 连接关心的事件
    uint32_t _events;

protected:
    handler_t _handler;
};